﻿namespace Microsoft.SharePoint.Client
{
    using Microsoft.SharePoint.Client.Utilities;
    using System;
    using System.ComponentModel;

    [ScriptType("SP.Principal", ServerTypeId="{8a76e712-17a1-4a40-b2df-cca7c060d78f}")]
    public class Principal : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public Principal(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "PrincipalType"))
                {
                    if (str == "Title")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Title"] = reader.ReadString();
                        return flag;
                    }
                    if (str == "LoginName")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["LoginName"] = reader.ReadString();
                        return flag;
                    }
                    if (str == "Id")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Id"] = reader.ReadInt32();
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                base.ObjectData.Properties["PrincipalType"] = reader.ReadEnum<Microsoft.SharePoint.Client.Utilities.PrincipalType>();
            }
            return flag;
        }

        [Remote]
        public int Id
        {
            get
            {
                base.CheckUninitializedProperty("Id");
                return (int) base.ObjectData.Properties["Id"];
            }
        }

        [Remote]
        public string LoginName
        {
            get
            {
                base.CheckUninitializedProperty("LoginName");
                return (string) base.ObjectData.Properties["LoginName"];
            }
        }

        [Remote]
        public Microsoft.SharePoint.Client.Utilities.PrincipalType PrincipalType
        {
            get
            {
                base.CheckUninitializedProperty("PrincipalType");
                return (Microsoft.SharePoint.Client.Utilities.PrincipalType) base.ObjectData.Properties["PrincipalType"];
            }
        }

        [Remote]
        public string Title
        {
            get
            {
                base.CheckUninitializedProperty("Title");
                return (string) base.ObjectData.Properties["Title"];
            }
            set
            {
                if (base.Context.ValidateOnClient)
                {
                    if (value == null)
                    {
                        throw ClientUtility.CreateArgumentNullException("value");
                    }
                    if ((value != null) && (value.Length > 0xff))
                    {
                        throw ClientUtility.CreateArgumentException("value");
                    }
                }
                base.ObjectData.Properties["Title"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Title", value));
                }
            }
        }
    }
}

